package com.xxxx.sink_operator;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.common.serialization.SerializationSchema;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.core.fs.FileSystem;
import org.apache.flink.streaming.api.datastream.DataStreamSink;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;

/**
 * @program: flink19Test
 * @description:
 * @author: CoreDao
 * @create: 2021-04-01 17:06
 **/

public class SinkWriteToSocket {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();


//        env.setParallelism(4);
        env.setParallelism(1);

        List<String> list = Arrays.asList("hello nihao", "hello nihao1", "hello nihao2","hello nihaos");

        DataStreamSource<String> dataStreamSource = env.fromCollection(list);

        dataStreamSource.writeToSocket("localhost", 9999, new SerializationSchema<String>() {
            @Override
            public byte[] serialize(String element) {
                String output = element + "\n";
                return output.getBytes();
            }
        });


        env.execute();
    }
}
